In [1]:
%load_ext autoreload
%autoreload 2

Biologically-inspired characterization of sparseness in natural images

Natural images follow statistics inherited by the structure of our physical (visual) environment. In particular, a prominent facet of this structure is that images can be described by a relatively sparse number of features. We designed a sparse coding algorithm biologically-inspired by the architecture of the primary visual cortex. We show here that coefficients of this representation exhibit a power-law distribution. The exponent of this distribution characterizes sparseness and varies from image to image. To investigate the role of this sparseness, we designed a new class of random textured stimuli with a controlled sparseness value inspired by measurements of natural images. Then, we provide with a method to modify the sparseness statistics observed in any image to match that of some class of natural images and provide perspectives for their use in neurophysiology.

Initialization

In [2]:
%run -i -t -N1 EUVIP_1_defaults.ipynb
The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload
Range of spatial frequencies:  [ 0.618   0.382   0.2361  0.1459  0.0902  0.0557  0.0344  0.0213]
Range of angles (in degrees):  [-82.5 -75.  -67.5 -60.  -52.5 -45.  -37.5 -30.  -22.5 -15.   -7.5   0.
   7.5  15.   22.5  30.   37.5  45.   52.5  60.   67.5  75.   82.5  90. ]
Final sparseness in the representation = 0.0026041666666666665
Final sparseness in the pyramid = 0.375

one example image

In [3]:
%run -i -t -N1 EUVIP_2_lena.ipynb
The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload
Range of spatial frequencies:  [ 0.618   0.382   0.2361  0.1459  0.0902  0.0557  0.0344  0.0213]
Range of angles (in degrees):  [-82.5 -75.  -67.5 -60.  -52.5 -45.  -37.5 -30.  -22.5 -15.   -7.5   0.
   7.5  15.   22.5  30.   37.5  45.   52.5  60.   67.5  75.   82.5  90. ]
Final sparseness in the representation = 0.0026041666666666665
Final sparseness in the pyramid = 0.375
-0.950759120364 0.891900615494
data_cache/EUVIP-lena_rec.npy
[   2    8   32  128  512 2048]

Running simulations on a set of natural images

In [4]:
%run -i -t -N1  EUVIP_3-sparsecoding.ipynb
The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload
Range of spatial frequencies:  [ 0.618   0.382   0.2361  0.1459  0.0902  0.0557  0.0344  0.0213]
Range of angles (in degrees):  [-82.5 -75.  -67.5 -60.  -52.5 -45.  -37.5 -30.  -22.5 -15.   -7.5   0.
   7.5  15.   22.5  30.   37.5  45.   52.5  60.   67.5  75.   82.5  90. ]
Final sparseness in the representation = 0.0026041666666666665
Final sparseness in the pyramid = 0.375
Overwriting ../test/experiment_sparseness.py
N_image =  100
In [5]:
%run -i -t -N1  EUVIP_4-statistics_natural_images.ipynb
The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload
The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload
Range of spatial frequencies:  [ 0.618   0.382   0.2361  0.1459  0.0902  0.0557  0.0344  0.0213]
Range of angles (in degrees):  [-82.5 -75.  -67.5 -60.  -52.5 -45.  -37.5 -30.  -22.5 -15.   -7.5   0.
   7.5  15.   22.5  30.   37.5  45.   52.5  60.   67.5  75.   82.5  90. ]
Final sparseness in the representation = 0.0026041666666666665
Final sparseness in the pyramid = 0.375
DATABASE  serre07_distractors
edgeslist shape =  (6, 4096, 100)
DATABASE  serre07_distractors
edgeslist shape =  (6, 4096, 100)
energy  [0.31821809582324467, 0.31821809582324467]
mean  [0.22679932047620086, 0.22679932047620086]
median  [0.16191300625300878, 0.16191300625300878]
sparseness  [1.4007480048996146, 1.4007480048996146]
Deviation from uniform =  1.05866847417
[-7.6363 -6.9421 -6.2479 -5.5537 -4.8595 -4.1653 -3.4711 -2.7768 -2.0826
 -1.3884 -0.6942]
[-86.25 -78.75 -71.25 -63.75 -56.25 -48.75 -41.25 -33.75 -26.25 -18.75
 -11.25  -3.75   3.75  11.25  18.75  26.25  33.75  41.25  48.75  56.25
  63.75  71.25  78.75  86.25  93.75]
[ 82.5 -30.   90.  ..., -45.  -67.5  75. ]
2017-02-07T10:16:38+01:00

CPython 3.6.0
IPython 5.2.1

compiler   : GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)
system     : Darwin
release    : 16.4.0
machine    : x86_64
processor  : i386
CPU cores  : 8
interpreter: 64bit

trying different fits

In [6]:
%run -i -t -N1  EUVIP_5-activities-fits.ipynb
The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload
Range of spatial frequencies:  [ 0.618   0.382   0.2361  0.1459  0.0902  0.0557  0.0344  0.0213]
Range of angles (in degrees):  [-82.5 -75.  -67.5 -60.  -52.5 -45.  -37.5 -30.  -22.5 -15.   -7.5   0.
   7.5  15.   22.5  30.   37.5  45.   52.5  60.   67.5  75.   82.5  90. ]
Final sparseness in the representation = 0.0026041666666666665
Final sparseness in the pyramid = 0.375
Requirement already up-to-date: lmfit in /usr/local/lib/python3.6/site-packages
Requirement already up-to-date: scipy in /usr/local/lib/python3.6/site-packages (from lmfit)
Requirement already up-to-date: numpy in /usr/local/lib/python3.6/site-packages (from lmfit)
[[Variables]]
    x_0:   0.01000024 (init= 0.05)
    B:     1.00003388 (init= 0.15)
[[Correlations]] (unreported correlations are <  0.100)
0.231645366197
0.617814533192
0.763945540392
0.832004497674
0.870567455937
0.895817066736
100 4096
Min= 3.3227408588e-05 Max= 0.0187982302149 shape= (100, 4096) Max= [ 0.0012  0.0023  0.0032  0.0025  0.0018  0.0081  0.009   0.0033  0.0026
  0.0039  0.0038  0.0026  0.0018  0.0024  0.0109  0.0188  0.0109  0.0077
  0.0036  0.0023  0.0031  0.0027  0.0034  0.0048  0.0031  0.0032  0.0029
  0.0025  0.0037  0.0062  0.0033  0.0027  0.0026  0.0032  0.0056  0.0061
  0.002   0.0081  0.0013  0.0025  0.0103  0.0036  0.0034  0.0049  0.005
  0.004   0.0034  0.003   0.0027  0.0017  0.0019  0.0028  0.0011  0.0026
  0.0026  0.0049  0.0041  0.0013  0.0021  0.0019  0.0018  0.0016  0.0033
  0.0026  0.0023  0.0031  0.0031  0.0034  0.0015  0.0029  0.0058  0.0049
  0.0012  0.0155  0.0023  0.0036  0.0067  0.0022  0.0039  0.0011  0.0105
  0.0017  0.0035  0.0034  0.0045  0.0035  0.0032  0.0033  0.0051  0.006
  0.0033  0.0013  0.0103  0.0033  0.006   0.0114  0.0073  0.004   0.0096
  0.0015]
bins used =  [ 0.      0.      0.      0.      0.      0.      0.      0.      0.
  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001
  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001
  0.0001  0.0001  0.0001  0.0001  0.0002  0.0002  0.0002  0.0002  0.0002
  0.0002  0.0002  0.0002  0.0002  0.0002  0.0003  0.0003  0.0003  0.0003
  0.0003  0.0003  0.0003  0.0004  0.0004  0.0004  0.0004  0.0004  0.0005
  0.0005  0.0005  0.0005  0.0006  0.0006  0.0006  0.0006  0.0007  0.0007
  0.0008  0.0008  0.0008  0.0009  0.0009  0.001   0.001   0.0011  0.0011
  0.0012  0.0012  0.0013  0.0014  0.0014  0.0015  0.0016  0.0017  0.0017
  0.0018  0.0019  0.002   0.0021  0.0022  0.0023  0.0025  0.0026  0.0027
  0.0029  0.003   0.0032  0.0033  0.0035  0.0037  0.0039  0.0041  0.0043
  0.0045  0.0047  0.0049  0.0052  0.0055  0.0057  0.006   0.0063  0.0066
  0.007   0.0073  0.0077  0.0081  0.0085  0.0089  0.0094  0.0099  0.0104
  0.0109  0.0115  0.012   0.0126  0.0133  0.014   0.0147  0.0154  0.0162
  0.017   0.0179  0.0188] (129,)
amplitude= 2.85238179461e-07 , +/-  3.6470296012e-07
rho= 1.4697728071 , +/-  0.169105803531
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/Users/lolo/quantic/science/Perrinet16EUVIP/notebooks/EUVIP_5-activities-fits.ipynb in <module>()
----> 1 imagelist, edgeslist, RMSE = mp.process(exp=experiment, name_database=name_database)
      2 value = edgeslist[4, ...].T

/Users/lolo/pool/science/BICV/SparseEdges/SparseEdges/SparseEdges.py in process(self, exp, name_database, note, noise)
    909                 open(txtname + '_lock', 'w').close() # touching
    910                 self.log.info(' >> Doing check_independence on %s ', txtname)
--> 911                 out = self.check_independence(self.cohistedges(edgeslist, symmetry=False, display=None), name_database, exp)
    912                 f = open(txtname, 'w')
    913                 f.write(out)

/Users/lolo/pool/science/BICV/SparseEdges/SparseEdges/SparseEdges.py in cohistedges(self, edgeslist, v_hist, prior, fig, a, symmetry, display, v_min, v_max, labels, mappable, radius, xticks, half, dolog, color, colorbar, cbar_label)
    544                                                  bins=(self.binedges_d, self.binedges_phi, self.binedges_theta, self.binedges_loglevel),
    545                                                  normed=False, # TODO check if correct True,
--> 546                                                  weights = weights
    547                                                 )
    548 #                 print v_hist_.sum(), v_hist_.min(), v_hist_.max(), d.ravel().shape

/usr/local/lib/python3.6/site-packages/numpy/lib/function_base.py in histogramdd(sample, bins, range, normed, weights)
    989         return zeros(nbin-2, int), edges
    990 
--> 991     flatcount = bincount(xy, weights)
    992     a = arange(len(flatcount))
    993     hist[a] = flatcount

ValueError: object too deep for desired array

DropLets as a power-law-sparse MotionCloud

In [7]:
%run -i -t -N1  EUVIP_6-droplets.ipynb

some book keeping for the notebook

In [8]:
%load_ext watermark
%watermark
The watermark extension is already loaded. To reload it, use:
  %reload_ext watermark
2017-02-07T10:16:57+01:00

CPython 3.6.0
IPython 5.2.1

compiler   : GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)
system     : Darwin
release    : 16.4.0
machine    : x86_64
processor  : i386
CPU cores  : 8
interpreter: 64bit
In [9]:
%load_ext version_information
%version_information numpy, scipy, matplotlib, sympy
The version_information extension is already loaded. To reload it, use:
  %reload_ext version_information
Out[9]:
SoftwareVersion
Python3.6.0 64bit [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)]
IPython5.2.1
OSDarwin 16.4.0 x86_64 i386 64bit
numpy1.12.0
scipy0.18.1
matplotlib2.0.0
sympy1.0
Tue Feb 07 10:16:57 2017 CET